package com.weicx.wuzhiops.config;

import com.weicx.wuzhiops.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author:
 * @date: 2022-12-06 14:27:33
 * @since: 1.0
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        List<String> excludeUrls = new ArrayList<>();
        // 排除登录接口
        excludeUrls.add("/ops/api/auth/login");

        // 排除swagger
        excludeUrls.add("/favicon.ico");
        excludeUrls.add("/error");
        excludeUrls.add("/swagger-resources/**");
        excludeUrls.add("/webjars/**");
        excludeUrls.add("/v2/**");
        excludeUrls.add("/doc.html");
        excludeUrls.add("**/swagger-ui.html");
        excludeUrls.add("/swagger-ui.html/**");


        // 注册拦截器
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")
                .excludePathPatterns(excludeUrls);      // 设置不拦截

    }



}
